<template>
  <!-- 下拉菜单 -->
  <el-dropdown trigger="click" @command="changeLanguage">
    <div>
      <svg-icon style="fill: white;font-size:20px" icon-class="language" />
    </div>
    <el-dropdown-menu slot="dropdown">
      <el-dropdown-item command="zh" :disabled="'zh'=== $i18n.locale ">中文</el-dropdown-item>
      <el-dropdown-item command="en" :disabled="'en'=== $i18n.locale ">en</el-dropdown-item>
    </el-dropdown-menu>
  </el-dropdown>
</template>

<script>
import Cookies from 'js-cookie'
export default {
  methods: {
    changeLanguage(lang) {
      // console.log(lang)
      // 1.把设置的语言环境存到本地
      Cookies.set('language', lang)
      // 2. 切换多语言
      this.$i18n.locale = lang
      // 3. 提示用户
      this.$message.success('切换多语言成功')
      // 强制刷新
      // window.location.reload()

      this.$store.dispatch('settings/changeSetting', { key: 'language', value: lang })
    }
  }
}
</script>

<style>

</style>
